package com.xqyq.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.xqyq.dao.MatchDao;
import com.xqyq.dao.SignDao;
import com.xqyq.dao.UserDao;
import com.xqyq.model.Match;
import com.xqyq.model.User;
import com.xqyq.model.Sign;

@Service
public class SignService {
	@Autowired
	private SignDao signDao;
	@Autowired
	private UserDao userDao;
	@Autowired
	private MatchDao matchDao;
	
	@Transactional
	public void sign(int user_id, int match_id){
		User user = userDao.getUser(user_id);
		Match match = matchDao.getMatch(match_id);
		Sign sign = new Sign();
		sign.setState(0);
		sign.setIsUpload(0);
		sign.setMatch(match);
		sign.setUser(user);
		signDao.addSign(sign);
	}
	
	@Transactional
	public void uploadUserSign(int user_id, int match_id){
		Sign sign = signDao.getSignByUserAndMatch(user_id,match_id);
		//
		sign.setIsUpload(1);
		
		
		signDao.updateSign(sign);
		System.out.println("1111111");
	}
	
	public List<Sign> getSignListNoPrize(int match_id){
		return signDao.getSignListNoPrize(match_id);
	}
	
	public List<Sign> getSignListNoCheck(){
		return signDao.getSignListNoCheck();
	}
	
	@Transactional
	public void passSign(int sign_id){
		signDao.passSign(sign_id);
	}
	
	@Transactional
	public void deleteSign(int sign_id){
		signDao.deleteSign(sign_id);
	}
	
	public List<Sign> getUserSignList(int user_id){
		return signDao.getUserSignList(user_id);
	}
	
	@Transactional
	public void removeUserPrize(int sign_id){
		signDao.removeUserPrize(sign_id);
	}
	
	@Transactional
	public void addUser_prize(int[] signList, int prize_id){
		for(int i=0; i< signList.length; i++){
			signDao.addUser_prize(signList[i], prize_id);
		}
	}
}
